import 'dart:convert' show json;

import 'package:flutter_common_app/data/protection.dart';

class SongDetailData {
  SongDetailData({
    this.name,
    this.id,
    this.pst,
    this.t,
    this.ar,
    this.alia,
    this.pop,
    this.st,
    this.rt,
    this.fee,
    this.v,
    this.crbt,
    this.cf,
    this.al,
    this.dt,
    this.h,
    this.m,
    this.l,
    this.a,
    this.cd,
    this.no,
    this.rtUrl,
    this.ftype,
    this.rtUrls,
    this.djId,
    this.copyright,
    this.s_id,
    this.mark,
    this.originCoverType,
    this.originSongSimpleData,
    this.resourceState,
    this.single,
    this.noCopyrightRcmd,
    this.mv,
    this.rtype,
    this.rurl,
    this.mst,
    this.cp,
    this.publishTime,
  });

  static List<SongDetailData> fromJsonList(List json){
    return json.map((item) => SongDetailData.fromJson(item)).toList();
  }

  factory SongDetailData.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Ar> ar = jsonRes['ar'] is List ? <Ar>[] : null;
    if (ar != null) {
      for (final dynamic item in jsonRes['ar']) {
        if (item != null) {
          tryCatch(() {
            ar.add(Ar.fromJson(asT<Map<String, dynamic>>(item)));
          });
        }
      }
    }

    final List<Object> alia = jsonRes['alia'] is List ? <Object>[] : null;
    if (alia != null) {
      for (final dynamic item in jsonRes['alia']) {
        if (item != null) {
          tryCatch(() {
            alia.add(asT<Object>(item));
          });
        }
      }
    }

    final List<Object> rtUrls = jsonRes['rtUrls'] is List ? <Object>[] : null;
    if (rtUrls != null) {
      for (final dynamic item in jsonRes['rtUrls']) {
        if (item != null) {
          tryCatch(() {
            rtUrls.add(asT<Object>(item));
          });
        }
      }
    }
    return SongDetailData(
      name: asT<String>(jsonRes['name']),
      id: asT<int>(jsonRes['id']),
      pst: asT<int>(jsonRes['pst']),
      t: asT<int>(jsonRes['t']),
      ar: ar,
      alia: alia,
      pop: asT<int>(jsonRes['pop']),
      st: asT<int>(jsonRes['st']),
      rt: asT<Object>(jsonRes['rt']),
      fee: asT<int>(jsonRes['fee']),
      v: asT<int>(jsonRes['v']),
      crbt: asT<Object>(jsonRes['crbt']),
      cf: asT<String>(jsonRes['cf']),
      al: Al.fromJson(asT<Map<String, dynamic>>(jsonRes['al'])),
      dt: asT<int>(jsonRes['dt']),
      h: H.fromJson(asT<Map<String, dynamic>>(jsonRes['h'])),
      m: M.fromJson(asT<Map<String, dynamic>>(jsonRes['m'])),
      l: L.fromJson(asT<Map<String, dynamic>>(jsonRes['l'])),
      a: asT<Object>(jsonRes['a']),
      cd: asT<String>(jsonRes['cd']),
      no: asT<int>(jsonRes['no']),
      rtUrl: asT<Object>(jsonRes['rtUrl']),
      ftype: asT<int>(jsonRes['ftype']),
      rtUrls: rtUrls,
      djId: asT<int>(jsonRes['djId']),
      copyright: asT<int>(jsonRes['copyright']),
      s_id: asT<int>(jsonRes['s_id']),
      mark: asT<int>(jsonRes['mark']),
      originCoverType: asT<int>(jsonRes['originCoverType']),
      originSongSimpleData: asT<Object>(jsonRes['originSongSimpleData']),
      resourceState: asT<bool>(jsonRes['resourceState']),
      single: asT<int>(jsonRes['single']),
      noCopyrightRcmd: asT<Object>(jsonRes['noCopyrightRcmd']),
      mv: asT<int>(jsonRes['mv']),
      rtype: asT<int>(jsonRes['rtype']),
      rurl: asT<Object>(jsonRes['rurl']),
      mst: asT<int>(jsonRes['mst']),
      cp: asT<int>(jsonRes['cp']),
      publishTime: asT<int>(jsonRes['publishTime']),
    );
  }

  String name;
  int id;
  int pst;
  int t;
  List<Ar> ar;
  List<Object> alia;
  int pop;
  int st;
  Object rt;
  int fee;
  int v;
  Object crbt;
  String cf;
  Al al;
  int dt;
  H h;
  M m;
  L l;
  Object a;
  String cd;
  int no;
  Object rtUrl;
  int ftype;
  List<Object> rtUrls;
  int djId;
  int copyright;
  int s_id;
  int mark;
  int originCoverType;
  Object originSongSimpleData;
  bool resourceState;
  int single;
  Object noCopyrightRcmd;
  int mv;
  int rtype;
  Object rurl;
  int mst;
  int cp;
  int publishTime;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'name': name,
    'id': id,
    'pst': pst,
    't': t,
    'ar': ar,
    'alia': alia,
    'pop': pop,
    'st': st,
    'rt': rt,
    'fee': fee,
    'v': v,
    'crbt': crbt,
    'cf': cf,
    'al': al,
    'dt': dt,
    'h': h,
    'm': m,
    'l': l,
    'a': a,
    'cd': cd,
    'no': no,
    'rtUrl': rtUrl,
    'ftype': ftype,
    'rtUrls': rtUrls,
    'djId': djId,
    'copyright': copyright,
    's_id': s_id,
    'mark': mark,
    'originCoverType': originCoverType,
    'originSongSimpleData': originSongSimpleData,
    'resourceState': resourceState,
    'single': single,
    'noCopyrightRcmd': noCopyrightRcmd,
    'mv': mv,
    'rtype': rtype,
    'rurl': rurl,
    'mst': mst,
    'cp': cp,
    'publishTime': publishTime,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Ar {
  Ar({
    this.id,
    this.name,
    this.tns,
    this.alias,
  });

  factory Ar.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Object> tns = jsonRes['tns'] is List ? <Object>[] : null;
    if (tns != null) {
      for (final dynamic item in jsonRes['tns']) {
        if (item != null) {
          tryCatch(() {
            tns.add(asT<Object>(item));
          });
        }
      }
    }

    final List<Object> alias = jsonRes['alias'] is List ? <Object>[] : null;
    if (alias != null) {
      for (final dynamic item in jsonRes['alias']) {
        if (item != null) {
          tryCatch(() {
            alias.add(asT<Object>(item));
          });
        }
      }
    }
    return Ar(
      id: asT<int>(jsonRes['id']),
      name: asT<String>(jsonRes['name']),
      tns: tns,
      alias: alias,
    );
  }

  int id;
  String name;
  List<Object> tns;
  List<Object> alias;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'id': id,
    'name': name,
    'tns': tns,
    'alias': alias,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class Al {
  Al({
    this.id,
    this.name,
    this.picUrl,
    this.tns,
    this.pic,
  });

  factory Al.fromJson(Map<String, dynamic> jsonRes) {
    if (jsonRes == null) {
      return null;
    }

    final List<Object> tns = jsonRes['tns'] is List ? <Object>[] : null;
    if (tns != null) {
      for (final dynamic item in jsonRes['tns']) {
        if (item != null) {
          tryCatch(() {
            tns.add(asT<Object>(item));
          });
        }
      }
    }
    return Al(
      id: asT<int>(jsonRes['id']),
      name: asT<String>(jsonRes['name']),
      picUrl: asT<String>(jsonRes['picUrl']),
      tns: tns,
      pic: asT<int>(jsonRes['pic']),
    );
  }

  int id;
  String name;
  String picUrl;
  List<Object> tns;
  int pic;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'id': id,
    'name': name,
    'picUrl': picUrl,
    'tns': tns,
    'pic': pic,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class H {
  H({
    this.br,
    this.fid,
    this.size,
    this.vd,
  });

  factory H.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : H(
    br: asT<int>(jsonRes['br']),
    fid: asT<int>(jsonRes['fid']),
    size: asT<int>(jsonRes['size']),
    vd: asT<int>(jsonRes['vd']),
  );

  int br;
  int fid;
  int size;
  int vd;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'br': br,
    'fid': fid,
    'size': size,
    'vd': vd,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class M {
  M({
    this.br,
    this.fid,
    this.size,
    this.vd,
  });

  factory M.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : M(
    br: asT<int>(jsonRes['br']),
    fid: asT<int>(jsonRes['fid']),
    size: asT<int>(jsonRes['size']),
    vd: asT<int>(jsonRes['vd']),
  );

  int br;
  int fid;
  int size;
  int vd;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'br': br,
    'fid': fid,
    'size': size,
    'vd': vd,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}

class L {
  L({
    this.br,
    this.fid,
    this.size,
    this.vd,
  });

  factory L.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : L(
    br: asT<int>(jsonRes['br']),
    fid: asT<int>(jsonRes['fid']),
    size: asT<int>(jsonRes['size']),
    vd: asT<int>(jsonRes['vd']),
  );

  int br;
  int fid;
  int size;
  int vd;

  Map<String, dynamic> toJson() => <String, dynamic>{
    'br': br,
    'fid': fid,
    'size': size,
    'vd': vd,
  };
  @override
  String toString() {
    return json.encode(this);
  }
}
